<?php


class CtableHelper extends AppHelper {
   var $helpers = array('Html');
    /** ********************************************************************************
     * bang: de hien thi
     * ********************************************************************************/	
    
  
  function bang($model,$cot,$dong){
    $n=count($cot);
    $m=count($dong);
    
    $kq='<table id="tables">';  
    //for($i=-1;$i<$m;$i++){
    
  
    $kq=$kq. '<th></th>';
               
            
    foreach($cot as $c):
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'</font></b></th>';
                  
   endforeach; 
  
    $i=0;   
    foreach ($dong as $d):
        $kq.='<tr>';
        
        
            $kq.='<td>'.$d.'</td>';
            for($j=0;$j<$n;$j++)
                  $kq=$kq. '<td><input type="text" name="data['.$model.']['.($i).']['.($j).']">
                      </input></td>';
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $kq.='</table>';
    
    return $kq;
    
    
  }

/** bangnhiemvu: Tao khung nhap lieu cho muc 2. Nhung congviec chinh, cong van, chi thi
 * 
 * @param   $model
 * @param   $dong
 * 
 * @return  ma HTML
 * */
    function Addtask($model,$dong,$border=0,$sonhom=2){
        $kq='';
        $n=28;
        $m=count($dong);
        
      //  $kq ='<input type="hidden" name="data['. $model .'][socot]" value="'. $n .'"/>';
        $kq.='<input type="hidden" name="data['. $model .'][sodong]" value="'. $m .'"/>';
  
       // print_r($dong);
        $kq.='<table border="'.$border.'" id="tables">';  
    //for($i=-1;$i<$m;$i++){
        
        $kq=$kq. '<th rowspan="2">STT</th>';
        $kq=$kq. '<th rowspan="2" colspan="2">Nhân viên</th>';
        
        
               
            
        for($i=2;$i<=7;$i++){
            $kq=$kq. '<th colspan="'.$sonhom.'"><b><font color="#CC0909">Thứ '
                      .$i.'</font></b></th>';
                  
        } 
        
        $kq=$kq. '<th colspan="'.$sonhom.'"><b><font color="#CC0909">Chủ nhật</font></b></th>';
        
        $kq=$kq. '<th rowspan="2">Thêm</th>';
    
       
        $kq.='<tr style="text-align: center">';
        for($i=1;$i<=7;$i++)
            //$kq.='<td>1</td><td>2</td><td>3</td><td>4</td>';
             for($k=0;$k<$sonhom;$k++)   
                $kq.='<td style="font-weight:bold"><font color="#FB9301">('.($k+1).')</td>';
        $kq.='</tr>';
        
        $stt=1;
        for ($i=0;$i<$m;$i++){
            $kq.='<tr>';
            
            $kq.='<td>';
            
            if($i>0){
                if($dong[$i-1]['Nhanvien']['manv']!=$dong[$i]['Nhanvien']['manv'])
                $kq.=$stt++;
            }
            else
                $kq.=$stt++;
                
        
            $kq.='<td>'.$dong[$i]['Nhanvien']['manv'].'</td><td>'.$dong[$i]['Nhanvien']['tennv'].'</td>';
    //de luu ma nhan vien
            $kq.='<input type="hidden" name="data['. $model .'][nv]['.$i.']" 
                            value="'. $dong[$i]['Tempnhiemvunv']['nhanvien_id'] .'"/>';
    
            for($j=0;$j<7;$j++){
                //de luu thu
            //    $kq.='<input type="hidden" name="data['. $model .'][thu]['.$i.']['.$j.']" 
              //              value="'. $j .'"/>';
                
                //k=0: noi dung cong viec
                //k=1: chi tieu
                //k=2: ket qua
                //k=3: ty le hoan thanh
                $kq=$kq. '<td><input type="text" size="20"
                            name="data['.$model.']['.($i).']['.($j).'][0]" type="textarea">
                            </input></td>';
                for($k=1;$k<$sonhom;$k++)
                    
                    if ($k==1||$k==4)
                        $kq=$kq. '<td><input type="text" 
                            name="data['.$model.']['.($i).']['.($j).']['.$k.']">
                            </input></td>';
                    else{
                        $kq=$kq. '<td><input type="text" 
                            name="data['.$model.']['.($i).']['.($j).']['.$k.']" class="text2">
                            </input></td>';
                    }
            }
        
            $kq.= '<td>'.$this->Html->link(__('Thêm', true), array('action' => 'addnv',
                    $dong[$i]['Tempnhiemvunv']['kehoach_id'],
                    $dong[$i]['Tempnhiemvunv']['nhanvien_id']),null,
                    sprintf(__('Trước khi THÊM bạn vui lòng lưu các công việc đã nhập,nếu không dữ liệu bạn nhập sẽ bị MẤT. Bạn có chắc muốn thêm?', true)));
             $kq.='</td>';
            $kq.='</tr>';
            
            
        
         }
    //}
    
    $kq.='</table>';
    
    return $kq;
    
    
  }
/** Edittask: Tao khung nhap lieu cho muc 2. Nhung congviec chinh, cong van, chi thi
 * @param   $model      model de luu tru csdl
 * @param   $dong       dong du lieu de lam tieu de dong
 * @param   $data       du lieu cu dua vao o nhap lieu
 * @param   idnv        Kiem tra xem la trang nhap cua nhan vien bt hay truong trung tam
 * @return  ma HTML
 * */
  
   function Edittask($model,$dong,$data,$border=0,$idnv=null){
        $kq='';
        $m=count($dong);
        
        $sonhom=2;
        //neu la nhan vien thi hien ca 4 cot moi nhom
        if(!empty($idnv))
            $sonhom=4;
        /*    
        $kq.='<div class="div_freezepanes_wrapper">';
        $kq.='<div class="div_verticalscroll" onmouseover="this.style.cursor=\'pointer\'">';
        $kq.='<div style="height:50%;" onmousedown="upp();" onmouseup="upp(1);"><img class="buttonUp" src="../img/uF035.png"></div>';
        $kq.='<div style="height:50%;" onmousedown="down();" onmouseup="down(1);"><img class="buttonDn" src="../img/uF036.png"></div>';
        $kq.='</div>';
        $kq.='<div class="div_horizontalscroll" onmouseover="this.style.cursor=\'pointer\'">';
        $kq.='<div style="float:left;width:30%;height:80%;" onmousedown="right();" onmouseup="right(1);"><img class="buttonRight" src="../img/uF033.png"/></div>';
        $kq.='<div style="float:right;width:30%;height:80%;" onmousedown="left();" onmouseup="left(1);"><img class="buttonLeft" src="../img/uF034.png"/></div>';
        $kq.='</div>';
        */
        $kq.='<input type="hidden" name="data['. $model .'][sodong]" value="'. $m .'"/>';
  
       // print_r($dong);
        $kq.='<table id="tables" border="'.$border.'">';
        //$kq.='<table cellpadding=2 style="border:1px solid #000;" id="t1" >';  
    //    $kq.='<tr onmouseover="this.style.background=#EEEEEE;" onmouseout="this.style.background="";">';
     //   $kq.='<tr onmouseover="this.style.background=\'#EEEEEE\';" onmouseout="this.style.background=\'\';">';   
        
        $kq=$kq. '<th class="th" rowspan="2" >STT</th>';
        $kq=$kq. '<th class="th" rowspan="2" colspan="2">Nhân viên</th>';
        for($i=2;$i<=7;$i++){
            $kq=$kq. '<th class="th" colspan="'.$sonhom.'"><b><font color="#CC0909">Thứ '
                      .$i.'</font></b></th>';
                  
        } 
        
        $kq=$kq. '<th class="th" colspan="'.$sonhom.'"><b><font color="#CC0909">Chủ nhật</font></b></th>';
        
        $kq=$kq. '<th class="th"rowspan="2">Thêm</th>';
    
       // $kq.='</tr>';
        
        
        $kq.='<tr style="text-align: center">';
     //   $kq.='<tr style="text-align: center" onmouseover="this.style.background=\'#EEEEEE\';" onmouseout="this.style.background=\'\';">';   
        
        for($i=1;$i<=7;$i++)
            //$kq.='<td>1</td><td>2</td><td>3</td><td>4</td>';
             for($k=0;$k<$sonhom;$k++)   
                $kq.='<td style="font-weight:bold"><font color="#FB9301">('.($k+1).')</td>';
        $kq.='</tr>';
        
        $stt=1;
        for ($i=0;$i<$m;$i++){
            $kq.='<tr>';
      //      $kq.='<tr onmouseover="this.style.background=\'#EEEEEE\';" onmouseout="this.style.background=\'\';">';      
        //    $kq.='<td nowrap>';
            $kq.='<td>';
            $giong=1;
            if($i>0){//xet xem 2 dong gan nhau co cung 1 nhan vien khong
                if($dong[$i-1]['Nhanvien']['manv']!=$dong[$i]['Nhanvien']['manv']){
                $kq.=$stt++;
                $giong=0;
                }
            }
            else
                $kq.=$stt++;
                
            $kq.='</td>';
        
            $kq.='<td nowrap>'.$dong[$i]['Nhanvien']['manv'].'</td><td>'.$dong[$i]['Nhanvien']['tennv'].'</td>';
    //de luu ma nhan vien
            $kq.='<input type="hidden" name="data['. $model .'][nv]['.$i.']" 
                            value="'. $dong[$i]['Tempnhiemvunv']['nhanvien_id'] .'"/>';
    
            for($j=0;$j<7;$j++){
                
                //k=0: noi dung cong viec
                //k=1: chi tieu
                //k=2: ket qua
                //k=3: ty le hoan thanh
                           
                            
                    if(empty($idnv)){/** TRUONG HOP TAI KHOAN CUA "TRUONG TT"
                                        * */        
                        $kq=$kq. '<td nowrap><input type="text" 
                                name="data['.$model.']['.($i).']['.($j).'][0]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['nhiemvu'].'"';
                   
                    
                        $kq.='  /></td>';
        //                $kq.='  />'.$data[(7*($i)+$j)]['Nvngay']['id'].'</td>';
                    
                        $kq=$kq. '<td nowrap><input type="text" 
                                name="data['.$model.']['.($i).']['.($j).'][1]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['chitieu'].'" class="text2"';
                   
                    
                    //NEU LA "TRUONG" THI 2 O NAY CAN HIDE
                    
                        $kq.=' /></td>';
               
                        $kq=$kq. '<input type="hidden" 
                                name="data['.$model.']['.($i).']['.($j).'][2]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['ketqua'].' class="text2">';
                        $kq.=' </input>';
                    
                        $kq=$kq. '<input type="hidden" 
                                name="data['.$model.']['.($i).']['.($j).'][3]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['tyle'].'">';
                        $kq.=' </input>';
                    
                    
                    }
                    else{/** TRUONG HOP TAI KHOAN CUA "NHAN VIEN BT"
                                        * */ 
                    //NEU LA NHAN VIEN THI 2 O NAY CAN HIDE
                        $kq=$kq. '<input type="hidden" 
                                name="data['.$model.']['.($i).']['.($j).'][0]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['nhiemvu'].'"';
                        
                        $kq.='  />';
                        $kq.='<td nowrap>'.$data[(7*($i)+$j)]['Nvngay']['nhiemvu'].'</td>';
                    
                    
                        $kq=$kq. '<input type="hidden" 
                                name="data['.$model.']['.($i).']['.($j).'][1]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['chitieu'].'"';
                  
                    
                        $kq.=' />';
              
                        $kq.='<td nowrap>'.$data[(7*($i)+$j)]['Nvngay']['chitieu'].'</td>';
                    
               
               //2 o duoi day se hien de nhan vien cap nhat ket qua
                        $kq=$kq. '<td nowrap><input type="text" 
                                name="data['.$model.']['.($i).']['.($j).'][2]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['ketqua'].'">';
                        $kq.=' </input></td>';
                    
                        $kq=$kq. '<td nowrap><input type="text" 
                                name="data['.$model.']['.($i).']['.($j).'][3]" 
                                value="'.$data[(7*($i)+$j)]['Nvngay']['tyle'].'">';
                        $kq.=' </input></td>';
                    }
                    
            }
            
            //neu la nhan vien thi khong them duoc cong viec moi
            if(empty($idnv)){
                $kq.= '<td nowrap>'.$this->Html->link(__('Thêm', true), array('action' => 'editnv',
                    $dong[$i]['Tempnhiemvunv']['kehoach_id'],$dong[$i]['Tempnhiemvunv']['nhanvien_id']))
                .'';
                if($giong==1&&$i!=0)
                //(xoa nguyen dong)                                
                    $kq.= '<br>'.$this->Html->link(__('Xóa', true), array('action' => 'delete',
                        $data[$i*7]['Nvngay']['id'],$data[$i*7+1]['Nvngay']['id'],
                        $data[$i*7+2]['Nvngay']['id'],$data[$i*7+3]['Nvngay']['id'],
                        $data[$i*7+4]['Nvngay']['id'],$data[$i*7+5]['Nvngay']['id'],
                        $data[$i*7+6]['Nvngay']['id'],
                        $data[$i*7]['Nvngay']['kehoach_id'],$dong[$i]['Tempnhiemvunv']['id']),null,
                        sprintf(__('Bạn có chắc muốn xóa NGUYÊN DÒNG dữ liệu này? Chú ý dữ liệu xóa không thể phục hồi!!', true)))
                    .'</td>';
            
            }
            $kq.='</tr>';
            
            
        
         }
    //}
    
    $kq.='</table>';
     $kq.='</div>';
    return $kq;
    
    
  }
  /**
   * hien thi ket qua nhap lieu cac cong viec
   * 
   * @param dong  Du lieu tieu de dong
   * @param data  Du lieu do vao khu trung tam cua bang
   * */
  //function Viewtask($dong,$data,$border){
//        $kq='';
//        $n=28;
//        $m=count($dong);
//        $cotlon=7;
//      
//        $kq.='<div class="base">';
//        
//        $kq.='<ul class="base-row">';
//        /*table 1*/
//       $kq.='<li>';
//       $kq.='<div style="width:300px">';
//        $kq.='<table id="tables" style="height:100%">';
//        
//        $kq=$kq. '<th rowspan="2">STT</th>';
//        $kq=$kq. '<th rowspan="1" colspan="2">Nhân viên</th>';
//        $kq.='<tr><th>Mã</th><th>Họ tên</th></tr>';
//        $stt=1;
//        for ($i=0;$i<$m;$i++){
//            $kq.='<tr>';
//            
//            $kq.='<td>';
//            $giong=1;
//            if($i>0){//xet xem 2 dong gan nhau co cung 1 nhan vien khong
//                if($dong[$i-1]['Nhanvien']['manv']!=$dong[$i]['Nhanvien']['manv']){
//                $kq.=$stt++;
//                $giong=0;
//                }
//            }
//            else
//                $kq.=$stt++;
//                
//            $kq.='</td>';
//        
//            $kq.='<td>'.$dong[$i]['Nhanvien']['manv'].'</td><td>'.$dong[$i]['Nhanvien']['tennv'].'</td>';
//            }
//        $kq.='</table>';
//        $kq.='</div>';
//        $kq.='</li>';  
//            //het table 1 
//          /*table 2*/
//         $kq.='<li >'; 
//          $kq.='<div style="width:700px; overflow:auto; background:#fff; top:0px;">';
//        $kq.='<table id="tables" style="height:100%" >';
//           
//        for($i=2;$i<=7;$i++){
//            $kq=$kq. '<th colspan="4"><b><font color="#CC0909">Thứ '
//                      .$i.'</font></b></th>';
//                  
//        } 
//        
//        $kq=$kq. '<th colspan="4"><b><font color="#CC0909">
//        Ch? nh?t</font></b></th>';
//        
//     
//       
//        $kq.='<tr style="text-align: center">';
//        for($i=1;$i<=$cotlon;$i++)
//        
//             for($k=0;$k<4;$k++)   
//                $kq.='<td style="font-weight:bold"><font color="#FB9301">('.($k+1).')</td>';
//        $kq.='</tr>';
//        
//        /** HET HIEN TIEU DE
//         * */
//        $stt=1;
//        for ($i=1;$i<=$m;$i++){
//            $kq.='<tr>';
//          
//            $kq.='<td>';
//            if($i>1){
//                if($dong[$i-2]['Nhanvien']['manv']!=$dong[$i-1]['Nhanvien']['manv'])
//                $kq.=$stt++;
//            }
//            else
//                $kq.=$stt++;
//            $kq.='</td>';
//        
//            $kq.='<td>'.$dong[$i-1]['Nhanvien']['manv'].'</td><td>'.$dong[$i-1]['Nhanvien']['tennv'].'</td>';
//    
//            for($j=1;$j<=$cotlon;$j++){
//               
//                    $kq=$kq. '<td>';
//                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['nhiemvu'];
//                    $kq.='</td>';
//                    
//                    $kq=$kq. '<td><font color="#330066"><strong>';
//                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['chitieu'];
//                    $kq.='</strong></font></td>';
//                    
//                    $kq=$kq. '<td><font color="#0000CC">';
//                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['ketqua'];
//                    $kq.='</font></td>';
//                    
//                    $kq=$kq. '<td><font color="#336600">';
//                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['tyle'];
//                    $kq.='</font></td>';
//            }
//        
//            
//            $kq.='</tr>';
//            
//            
//        
//         }
//    $kq.='</table>';
//    $kq.='</div>';
//    $kq.='</li>';
//    
//    /**het table 2*/
//    $kq.='</ul>';
//    $kq.='</div>';
//    
//    return $kq;
//    
//    
//  }

 function Viewtask($dong,$data,$border){
        $kq='';
        $n=28;
        $m=count($dong);
        $cotlon=7;
      
        $kq.='<table border="'.$border.'" id="tables">';  
     
    
    /** hien tieu de cua bang
     * */    
        $kq=$kq. '<th rowspan="2">STT</th>';
        $kq=$kq. '<th rowspan="2" colspan="2">Nhân viên</th>';
        
        
               
            
        for($i=2;$i<=7;$i++){
            $kq=$kq. '<th colspan="4"><b><font color="#CC0909">Thứ '
                      .$i.'</font></b></th>';
                  
        } 
        
        $kq=$kq. '<th colspan="4"><b>
        Chủ nhật</font></b></th>';
        
     
       
        $kq.='<tr style="text-align: center">';
        for($i=1;$i<=$cotlon;$i++)
            //$kq.='<td>1</td><td>2</td><td>3</td><td>4</td>';
             for($k=0;$k<4;$k++)   
                $kq.='<td style="font-weight:bold"><font color="#FB9301">('.($k+1).')</td>';
        $kq.='</tr>';
        
        /** HET HIEN TIEU DE
         * */
        $stt=1;
        for ($i=1;$i<=$m;$i++){
            $kq.='<tr>';
          
            $kq.='<td>';
            if($i>1){
                if($dong[$i-2]['Nhanvien']['manv']!=$dong[$i-1]['Nhanvien']['manv'])
                $kq.=$stt++;
            }
            else
                $kq.=$stt++;
            $kq.='</td>';
        
            $kq.='<td>'.$dong[$i-1]['Nhanvien']['manv'].'</td><td>'.$dong[$i-1]['Nhanvien']['tennv'].'</td>';
    
            for($j=1;$j<=$cotlon;$j++){
                //k=0: noi dung cong viec
                //k=1: chi tieu
                //k=2: ket qua
                //k=3: ty le hoan thanh
                    $kq=$kq. '<td>';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['nhiemvu'];
                    $kq.='</td>';
                    
                    $kq=$kq. '<td><font color="#330066"><strong>';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['chitieu'];
                    $kq.='</strong></font></td>';
                    
                    $kq=$kq. '<td><font color="#0000CC">';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['ketqua'];
                    $kq.='</font></td>';
                    
                    $kq=$kq. '<td><font color="#336600">';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['tyle'];
                    $kq.='</font></td>';
            }
        
            
            $kq.='</tr>';
            
            
        
         }
    //}
    
    $kq.='</table>';
    
    return $kq;
    
    
  }
  
  
  
   function Viewtaskexcel($dong,$data,$border,$mau='d5d5d5'){
        $kq='';
        $n=28;
        $m=count($dong);
        $cotlon=7;
      
        $kq.='<table border="'.$border.'">';  
     
    
    /** hien tieu de cua bang
     * */    
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" rowspan="2">STT</th>';
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" rowspan="2" colspan="2">Nhân viên</th>';
        
        
               
            
        for($i=2;$i<=7;$i++){
            $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" colspan="4"><b><font color="#CC0909">Thứ '
                      .$i.'</font></b></th>';
                  
        } 
        
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" colspan="4"><b>
        Chủ nhật</font></b></th>';
        
     
       
        $kq.='<tr style="text-align: center">';
        for($i=1;$i<=$cotlon;$i++)
            //$kq.='<td>1</td><td>2</td><td>3</td><td>4</td>';
             {
                $kq.='<td style="background: #'.$mau.'; font-weight: bold">Nhiệm<br>vụ</td>';
                $kq.='<td style="background: #'.$mau.'; font-weight: bold">Chỉ<br>tiêu</td>';
                $kq.='<td style="background: #'.$mau.'; font-weight: bold">Kết<br>quả</td>';
                $kq.='<td style="background: #'.$mau.'; font-weight: bold">%<br>hoàn<br>thành</td>';
             
             
             }
        $kq.='</tr>';
        
        /** HET HIEN TIEU DE
         * */
        $stt=1;
        for ($i=1;$i<=$m;$i++){
            $kq.='<tr>';
          
            $kq.='<td>';
            if($i>1){
                if($dong[$i-2]['Nhanvien']['manv']!=$dong[$i-1]['Nhanvien']['manv'])
                $kq.=$stt++;
            }
            else
                $kq.=$stt++;
            $kq.='</td>';
        
            $kq.='<td>'.$dong[$i-1]['Nhanvien']['manv'].'</td><td>'.$dong[$i-1]['Nhanvien']['tennv'].'</td>';
    
            for($j=1;$j<=$cotlon;$j++){
                //k=0: noi dung cong viec
                //k=1: chi tieu
                //k=2: ket qua
                //k=3: ty le hoan thanh
                    $kq=$kq. '<td>';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['nhiemvu'];
                    $kq.='</td>';
                    
                    $kq=$kq. '<td><font color="#330066"><strong>';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['chitieu'];
                    $kq.='</strong></font></td>';
                    
                    $kq=$kq. '<td><font color="#0000CC">';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['ketqua'];
                    $kq.='</font></td>';
                    
                    $kq=$kq. '<td><font color="#336600">';
                    $kq.=$data[($cotlon*($i-1)+$j-1)]['Nvngay']['tyle'];
                    $kq.='</font></td>';
            }
        
            
            $kq.='</tr>';
            
            
        
         }
    //}
    
    $kq.='</table>';
    
    return $kq;
    
    
  }
    /** ********************************************************************************
     * bang: de hien thi 
     * ********************************************************************************/	

  function bangluu($model,$cot,$dong){
    $n=count($cot);
    $m=count($dong);
    
    $kq='<table>';  
    //for($i=-1;$i<$m;$i++){
    
  
    $kq=$kq. '<th></th>';
               
            
    foreach($cot as $c):
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'</font></b></th>';
                  
   endforeach; 
  
    $i=0;   
    foreach ($dong as $d):
        $kq.='<tr>';
        
        
            $kq.='<td>'.$d.'</td>';
            for($j=0;$j<$n;$j++)
                  $kq=$kq. '<td><input type="text" name="data['.$model.']['.($i).']['.($j).']">
                      </input></td>';
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $kq.='</table>';
    
    return $kq;
    
    
  }

    /** ********************************************************************************
     * bang: hien thi them input KAHT
     * ********************************************************************************/	
    
  
    
  function addtable($model,$cols,$rows){
    $colnum=count($cols);
    $rownum=count($rows);
    $result ='<input type="hidden" name="data['. $model .'][colnum]" value="'. $colnum .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
    $result.='<input type="hidden" class="cellvalue" value=""/>';
    $result.='<table id="tables">';  
    
    $result.='<th></th>';
    
    $i=0;
    foreach($cols as $col_id => $display_c):
    	$result.='<input type="hidden" name="data['. $model .'][col]['. $i .']" value="'. $col_id .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c.'</font></b></th>';
          $i++;
   endforeach; 
  $result.='<th class="tong">Tổng</th>';
    $i=0;   
    foreach ($rows as $row_id=>$display_r):
        $result.='<tr>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum;$j++)
                  $result.='<td><input type="text" class="text" id="'.$i.'" name="data['.$model.']['.($i).']['.($j).']"></td>';
            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .']["tong"]" disabled="disabled"></td>';
        
                    
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $result.='</table>';
    
    return $result;
    
  }

  
  
	function addtableknv($model,$cols,$rows,$soluong=null)
	{
	    $colnum=count($cols);
	    $rownum=count($rows);
	    $result ='<input type="hidden" name="data['. $model .'][colnum]" value="'. $colnum .'"/>';
	    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
	    $result.='<input type="hidden" class="cellvalue" value=""/>';
	    $result.='<table id="tables">';  
	    
	    $result.='<th></th>';
	    
	    $i=0;
	    foreach($cols as $col_id => $display_c):
	    	$result.='<input type="hidden" name="data['. $model .'][col]['. $i .']" value="'. $col_id .'"/>';
	        $result.='<th><b><font color="#CC0909">'.
	                      $display_c.'</font></b></th>';
	          $i++;
	   endforeach; 
	  $result.='<th class="tong">Tổng</th>';
	    $i=0;   
	    foreach ($rows as $row_id=>$display_r):
	    	$sl =$soluong[$display_r];
	    	if($sl==0)
	    		$sotru = 0;
	    	else
	    	{
	    		$sotru =(int)($sl/$colnum);
	    		if($sotru==0)
	    			$sotru = 1;
	    	}
	        $result.='<tr>';
	        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
	            $result.='<td>'.$display_r.'</td>';
	            $tng = 0 ;
	            for($j=0;$j<$colnum;$j++)
	            {
	            	if($j==$colnum-1)
	            	{
	            		$sotru = $sl;
	            		$sl =0;
	            	}
	            	else 
	            	{
	            		if($sl!=0)
	            			$sl =$sl - $sotru;
	            		else
	            			$sotru=0;
	            	}
	            	if($sl<0)
	            	{
	            		$sotru = $sl+$sotru;
	            		$sl=0;
	            	}   
	                  $result.='<td><input type="text" class="text" id="'.$i.'" name="data['.$model.']['.($i).']['.($j).']" value="'. $sotru .'"></td>';
	                  $tng +=$sotru;
	            }
	            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .']["tong"]" disabled="disabled" value="'.$tng.'"></td>';
	        
	                    
	        $result.='</tr>';
	        
	        $i++;
	        
	     endforeach;  
	    //}
	    
	    $result.='</table>';
	    
	    return $result;
    
  }
  /** ********************************************************************************
     * bang: hien thi sua input KAHT
     * ********************************************************************************/	

   function edittable($model,$cols,$rows,$datasl,$dataid){
    $colnum=count($cols);
    $rownum=count($rows);
    $result ='<input type="hidden" name="data['. $model .'][colnum]" value="'. $colnum .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
    $result.='<input type="hidden" class="cellvalue" value=""/>';
    $result.='<table id="tables">';  
    
    $result.='<th></th>';
    
    $i=0;
    foreach($cols as $col_id => $display_c):
    	$result.='<input type="hidden" name="data['. $model .'][col]['. $i .']" value="'. $col_id .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c.'</font></b></th>';
          $i++;
   endforeach; 
  $result.='<th class="tong">Tổng</th>';
    $i=0;
    foreach ($rows as $row_id=>$display_r):
        $result.='<tr>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
            $result.='<td>'.$display_r.'</td>';
            $tong=0;
            for($j=0;$j<$colnum;$j++)
            {
            	$tong +=$datasl[$i][$j];
            	$result.='<input type="hidden" name="data['. $model .'][id]['.($i).']['.($j).']" value="'. $dataid[$i][$j] .'"/>';
                $result.='<td><input type="text" class="text" id="'.$i.'" name="data['.$model.']['.($i).']['.($j).']" value="'. $datasl[$i][$j] .'"></td>';
            }
            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .']["tong"] disabled="disabled" value="'. $tong .'"></td>';
        
                    
        $result.='</tr>';
        
        $i++;
        
     endforeach;  

    
    $result.='</table>';
    
    return $result;
    
  }
  
   /** ********************************************************************************
     * bang: hien thi KAHT
     * @param $data[$row][$col]: dung cho excel
     * ********************************************************************************/  
    
  function showe($cols,$rows,$data,$border=1,$mau='d5d5d5'){
    $colnum=count($cols);
    $rownum=count($rows);
    $result='<table border="'.$border.'">';  
    
    $result.='<th style="background: #'.$mau.'; font-weight: bold"></th>';
    
    foreach($cols as $col_id => $display_c):
        $result.='<th style="background: #'.$mau.'; font-weight: bold"><b><font color="#CC0909">'.
                      $display_c.'</font></b></th>';
   endforeach; 
  
    $i=0;   
    foreach ($rows as $row_id=>$display_r):
        $result.='<tr>';
        
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum;$j++)
                  $result=$result. '<td>'. $data[$i][$j] .'</td>';
        
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $result.='</table>';
    
    return $result;
    
    
  }
  
   function show($cols,$rows,$data,$border=0){
    $colnum=count($cols);
    $rownum=count($rows);
    $result='<table id="tables" border="'.$border.'">';  
    
    $result.='<th></th>';
    
    foreach($cols as $col_id => $display_c):
        $result.='<th><b><font color="#CC0909">'.
                      $display_c.'</font></b></th>';
   endforeach; 
  
    $i=0;   
    foreach ($rows as $row_id=>$display_r):
        $result.='<tr>';
        
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum;$j++)
                  $result=$result. '<td>'. ((strpos($data[$i][$j], '%')===false)?number_format($data[$i][$j],0,',','.'):$data[$i][$j]) .'</td>';
        
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $result.='</table>';
    
    return $result;
    
    
  }
 /** ********************************************************************************
     * bang: hien thi them input KAHT
     * @param $cols_1 danh sach cac cot table1
     * @param $cols_2 danh sach cac cot table2
     * @param $rows danh sach hang
     * ********************************************************************************/	
    
  function add_2_table($model,$cols_1,$cols_2,$rows){
    $colnum1=count($cols_1);
    $colnum2 = count($cols_2);
    $rownum=count($rows);
    $result ='<input type="hidden" name="data['. $model .'][colnum1]" value="'. $colnum1 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][colnum2]" value="'. $colnum2 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
    $result.='<input type="hidden" class="cellvalue" value=""/>';
    $result.='<table id="tables">';  
    
    $result.='<th></th>';
    
    $i=0;
    foreach($cols_1 as $col_id_1 => $display_c_1):
    	$result.='<input type="hidden" name="data['. $model .'][col1]['. $i .']" value="'. $col_id_1 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_1.'</font></b></th>';
          $i++;
   endforeach; 
    $i=0;
    foreach($cols_2 as $col_id_2 => $display_c_2):
    	$result.='<input type="hidden" name="data['. $model .'][col2]['. $i .']" value="'. $col_id_2 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_2.'</font></b></th>';
          $i++;
   endforeach; 
  $result.='<th class="tong">Tổng</th>';
    $i=0;   
    foreach ($rows as $row_id=>$display_r):
        $result.='<tr>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum1;$j++)
                  $result.='<td><input type="text" class="text1" id="[col_1]['.$i.']" name="data['.$model.'][col_1]['.($i).']['.($j).']"></td>';
            for($j=0;$j<$colnum2;$j++)
                  $result.='<td><input type="text" class="text2" id="'.$i.'" name="data['.$model.'][col_2]['.($i).']['.($j).']"></td>';
            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .'][tong]" disabled="disabled"></td>';
                         
        $result.='</tr>';
        
        $i++;
        
     endforeach;      
    $result.='</table>';
    
    return $result;
    
  }

 /** ********************************************************************************
     * bang: hien thi 2 loai col chung row  KAHT
     * @param $cols_1 DS col 1
     * @param $cols_2 DS col 2
     * @param $rows DS row
     * @param $data_1 data col 1
     * @param $data_2 data col 2 
     * ********************************************************************************/  
    
  function show_2_table($cols_1,$cols_2,$rows,$data_1,$data_2){
   $colnum1=count($cols_1);
    $colnum2 = count($cols_2);
    $rownum=count($rows);
    $result='<table id="tables">';  
    
    $result.='<th></th>';
    
   /*
    * in loai col 1
    */ 
   foreach($cols_1 as $col_id_1 => $display_c_1):
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_1.'</font></b></th>';
   endforeach;
   
   /*
    * in loai col 2
    */ 
    foreach($cols_2 as $col_id_2 => $display_c_2):
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_2.'</font></b></th>';
   endforeach;
   
   /*
    * in data cua tung loai col
    */
    $i=0;   
   // foreach ($rows as $row_id=>$display_r):
   for($j=0;$j<$rownum;$j++)
   {
        $result.='<tr>';
            $result.='<td>'.$rows[$j].'</td>';
            //for($j=0;$j<$colnum1;$j++)
            for($i=0;$i<$colnum1;$i++)
            //foreach ($data_1 as $keydt1 => $valuedt1)
                  $result.='<td>'.$data_1[$j][0].'</td>';
            for($i=0;$i<$colnum2;$i++)
                  $result=$result. '<td>'. ((strpos($data_2[$j][$i], '%')===false)?number_format($data_2[$j][$i],0,',','.'):$data_2[$j][$i]) .'</td>';
        
        $result.='</tr>';        
   }  
    //}
    
    $result.='</table>';
    
    return $result;
    
    
  }
  
/** ********************************************************************************
     * bang: hien thi them input KAHT
     * @param $cols_1 danh sach cac cot table1
     * @param $cols_2 danh sach cac cot table2
     * @param $rows danh sach hang
     * @param $data1 data col 1
     * @param $data2 data col 2
     * @param $dataid1 id data 1
     * @param $dataid2 id data 2
     * ********************************************************************************/	
    
  
    
  function show_2_table_1($model,$cols_1,$cols_2,$rows,$data1,$dataid1,$data2,$dataid2){
    $colnum1=count($cols_1);
    $colnum2 = count($cols_2);
    $rownum=count($rows);
    $result ='<input type="hidden" name="data['. $model .'][colnum1]" value="'. $colnum1 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][colnum2]" value="'. $colnum2 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
    $result.='<input type="hidden" class="cellvalue" value=""/>';
    $result.='<table id="tables">';  
    
    $result.='<th></th>';
    
    $i=0;
    foreach($cols_1 as $col_id_1 => $display_c_1):
    	$result.='<input type="hidden" name="data['. $model .'][col1]['. $i .']" value="'. $col_id_1 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_1.'</font></b></th>';
          $i++;
   endforeach; 
    $i=0;
    foreach($cols_2 as $col_id_2 => $display_c_2):
    	$result.='<input type="hidden" name="data['. $model .'][col2]['. $i .']" value="'. $col_id_2 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_2.'</font></b></th>';
          $i++;
   endforeach; 
  $result.='<th class="tong">Tổng</th>';
    $i=0;
    $tong=0;   
    foreach ($rows as $row_id=>$display_r):
    $tong=0;
        $result.='<tr>';
        	$result.='<input type="checkbox" name="data['. $model .'][checkbox][row]['. $i .']" value="'. $row_id .'"/>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum1;$j++)
            {
            	$result.='<input type="hidden" name="data['. $model .'][col_1][id]['.($i).']['.($j).']" value="'. $dataid1[$i][$j] .'"/>';
                $result.='<td>'.$data1[$j][0].'</td>';
            }
            for($j=0;$j<$colnum2;$j++)
            {	
            	$tong +=$data2[$i][$j];
            	$result.='<input type="hidden" name="data['. $model .'][col_2][id]['.($i).']['.($j).']" value="'. $dataid2[$i][$j] .'"/>';
                $result.='<td>'. $data2[$i][$j] .'</td>';
            }
            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .'][tong]" disabled="disabled" value="'. $tong .'"></td>';
                         
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    
    $result.='</table>';
    
    return $result;
    
  }
  
/** ********************************************************************************
     * bang: hien thi them input KAHT
     * @param $cols_1 danh sach cac cot table1
     * @param $cols_2 danh sach cac cot table2
     * @param $rows danh sach hang
     * @param $data1 data col 1
     * @param $data2 data col 2
     * @param $dataid1 id data 1
     * @param $dataid2 id data 2
     * ********************************************************************************/	
      
  function edit_2_table($model,$cols_1,$cols_2,$rows,$data1,$dataid1,$data2,$dataid2){
    $colnum1=count($cols_1);
    $colnum2 = count($cols_2);
    $rownum=count($rows);
    $result ='<input type="hidden" name="data['. $model .'][colnum1]" value="'. $colnum1 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][colnum2]" value="'. $colnum2 .'"/>';
    $result.='<input type="hidden" name="data['. $model .'][rownum]" value="'. $rownum .'"/>';
    $result.='<input type="hidden" class="cellvalue" value=""/>';
    $result.='<table id="tables">';  
    
    $result.='<th></th>';
    
    $i=0;
    foreach($cols_1 as $col_id_1 => $display_c_1):
    	$result.='<input type="hidden" name="data['. $model .'][col1]['. $i .']" value="'. $col_id_1 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_1.'</font></b></th>';
          $i++;
   endforeach; 
    $i=0;
    foreach($cols_2 as $col_id_2 => $display_c_2):
    	$result.='<input type="hidden" name="data['. $model .'][col2]['. $i .']" value="'. $col_id_2 .'"/>';
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_2.'</font></b></th>';
          $i++;
   endforeach; 
  $result.='<th class="tong">Tổng</th>';
    $i=0;
    $tong=0;   
    foreach ($rows as $row_id=>$display_r):
    $tong=0;
        $result.='<tr>';
        	$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $row_id .'"/>';
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum1;$j++)
            {
            	$result.='<input type="hidden" name="data['. $model .'][col_1][id]['.($i).']['.($j).']" value="'. $dataid1[$i][$j] .'"/>';
                $result.='<td><input type="text" class="text1" id="[col_1]['.$i.']" name="data['.$model.'][col_1]['.($i).']['.($j).']" value="'. $data1[$i][$j] .'"></td>';
            }
            for($j=0;$j<$colnum2;$j++)
            {	
            	$tong +=$data2[$i][$j];
            	$result.='<input type="hidden" name="data['. $model .'][col_2][id]['.($i).']['.($j).']" value="'. $dataid2[$i][$j] .'"/>';
                $result.='<td><input type="text" class="text2" id="'.$i.'" name="data['.$model.'][col_2]['.($i).']['.($j).']" value="'. $data2[$i][$j] .'"></td>';
            }
            $result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .'][tong]" disabled="disabled" value="'. $tong .'"></td>';
                         
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    
    $result.='</table>';
    
    return $result;
    
  }

 /** ********************************************************************************
     * bang: hien thi them input group
     * @author KAHT
     * @param $cols cot ching cua table array-form: $cols[Group][id]=display
     * @param $rows danh sach chi muc hang
     * @param $groups danh sach GROUP
     * ********************************************************************************/	
       
  function addtable_2($model,$cols,$rows,$groups)
  {
  	$result='<input type="hidden" class="cellvalue" value=""/>';
  	$result.= '<table id="tables">';
  	$result.='<th rowspan=2>Sản phẩm</th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th colspan='.count($cols[$keyg]).' align="center">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<th rowspan=2 class="tong">Tổng</th>';
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th>'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';
  	$i=0;
  	foreach ($rows as $keyr => $valuer):
  		$result.='<tr>';
  		$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $keyr .'"/>';
  		$result.='<td>'.$valuer.'</td>';
  		$j=0;
  		foreach ($cols as $keyc => $valuec):
  			foreach ($valuec as $keyc1 => $valuec1):
  				$result.='<td><input type="text" class="text" id="'.$i.'" name="data['.$model.'][data_tb]['.($i).']['.($j).']"></td>';
  				$j++;
  			endforeach;
  		endforeach;
  		$result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .']["tong"]" disabled="disabled"></td>';
  		$i++;
  		$result.='</tr>';
  	endforeach;
  	$result .= '</table>';
    return $result;
    
  }
  
 /** ********************************************************************************
     * bang: hien thi them input group
     * @author KAHT
     * @param $cols cot chinh cua table array-form: $cols[Group][id]=display
     * @param $rows danh sach chi muc hang
     * @param $groups danh sach GROUP
     * ********************************************************************************/	
    
  
    
  function showtable_2($model,$cols,$rows,$groups,$data,$datakh,$tenkh='',$border=0)
  {
  	$result= '<table id="tables" border="'.$border.'">';
  	$result.='<th rowspan=2></th>';
  	$result.='<th rowspan=2 class="tong">'.$tenkh.'</th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th colspan='.count($cols[$keyg]).' align="center">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<th rowspan=2 class="tong">Tổng</th>';
  	$result.='<th rowspan=2 class="tong">% Hoàn Thành</th>';
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th>'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';
  	$i=0;
  	foreach ($rows as $keyr => $valuer):
  		$result.='<tr>';
  		$result.='<td>'.$valuer.'</td>';
  		$result.='<td>'.number_format($datakh[$keyr],0,',','.').'</td>';
  		$slkh= $datakh[$keyr];
  		$j=0;
  		$tong=0;
  		foreach ($cols as $keyc => $valuec):
  			foreach ($valuec as $keyc1 => $valuec1):
  				$result.='<td>'.((strpos($data[$keyr][$keyc1], '%')===false)?number_format($data[$keyr][$keyc1],0,',','.'):$data[$keyr][$keyc1]) .'</td>';
  				$tong+=$data[$keyr][$keyc1];
  				$j++;
  			endforeach;
  		endforeach;
  		$result.='<td>'.((strpos($tong, '%')===false)?number_format($tong,0,',','.'):$tong).'</td>';
  		$result.='<td>'.(($slkh!=0)?round($tong*100/$slkh,2):'').'%</td>';
  		$i++;
  		$result.='</tr>';
  	endforeach;
  	$result .= '</table>';
    return $result;
    
  }

	function showtable_2e($model,$cols,$rows,$groups,$data,$datakh,$tenkh='',$border=0,$mau='d5d5d5')
  {
  	$result= '<table  border="'.$border.'">';
  	$result.='<th style="background: #'.$mau.'; font-weight: bold" rowspan=2></th>';
  	$result.='<th style="background: #'.$mau.'; font-weight: bold" rowspan=2 class="tong">'.$tenkh.'</th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th style="background: #'.$mau.'; font-weight: bold" colspan='.count($cols[$keyg]).' align="center">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<th style="background: #'.$mau.'; font-weight: bold" rowspan=2 class="tong">Tổng</th>';
  	$result.='<th style="background: #'.$mau.'; font-weight: bold" rowspan=2 class="tong">% Hoàn Thành</th>';
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th>'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';
  	$i=0;
  	foreach ($rows as $keyr => $valuer):
  		$result.='<tr>';
  		$result.='<td>'.$valuer.'</td>';
  		$result.='<td>'.$datakh[$keyr].'</td>';
  		$slkh= $datakh[$keyr];
  		$j=0;
  		$tong=0;
  		foreach ($cols as $keyc => $valuec):
  			foreach ($valuec as $keyc1 => $valuec1):
  				$result.='<td>'.$data[$keyr][$keyc1] .'</td>';
  				$tong+=$data[$keyr][$keyc1];
  				$j++;
  			endforeach;
  		endforeach;
  		$result.='<td>'.$tong.'</td>';
  		$result.='<td>'.$tong*100/$slkh.'%</td>';
  		$i++;
  		$result.='</tr>';
  	endforeach;
  	$result .= '</table>';
    return $result;
    
  }
  
  
  /** ********************************************************************************
     * bang: hien thi them input group
     * @author KAHT
     * @param $cols cot chinh cua table array-form: $cols[Group][id]=display
     * @param $rows danh sach chi muc hang
     * @param $groups danh sach GROUP
     * @data  $data du lieu theo $rows va $cols
     * ********************************************************************************/	
    
  
    
  function showtable_lk($model,$cols,$rows,$groups,$data,$tonghh,$border=null)
  {
    if(empty($border)){
  	     $result= '<table id="tables">';
         $result.='<th rowspan=2></th>';
  	$result.='<th rowspan=2 style="color: #0515E7">Tổng Lũy Kế Tháng</th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th colspan='.count($cols[$keyg]).' align="center" style="color:#000">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th>'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';

    }
    else{
   	     $result= '<table border="'.$border.'">';
         $result.='<th style="background: #d5d5d5; font-weight: bold" rowspan=2></th>';
  	$result.='<th style="background: #d5d5d5; font-weight: bold" rowspan=2 style="color: #0515E7">Tổng Lũy Kế Tháng</th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th style="background: #d5d5d5; font-weight: bold" colspan='.count($cols[$keyg]).' align="center" style="color:#000">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th style="background: #d5d5d5; font-weight: bold">'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';

    }
  	  	$i=0;
  	//debug($tong);
  	foreach ($rows as $keyr => $valuer):
  		$result.='<tr>';
  		$result.='<td>'.$valuer.'</td>';
  		$result.='<td>'.((strpos($tonghh[$keyr], '%')===false)?number_format($tonghh[$keyr],0,',','.'):$tonghh[$keyr]).'</td>';
  		$j=0;
  		foreach ($cols as $keyc => $valuec):
  			foreach ($valuec as $keyc1 => $valuec1):
  				$result.='<td>'.((strpos($data[$keyr][$keyc1], '%')===false)?number_format($data[$keyr][$keyc1],0,',','.'):$data[$keyr][$keyc1]) .'</td>';
  				$j++;
  			endforeach;
  		endforeach;
  		$i++;
  		$result.='</tr>';
  	endforeach;
  	$result .= '</table>';
    return $result;
    
  }
  
  
  /** ********************************************************************************
     * bang: hien thi them input group
     * @author KAHT
     * @param $cols cot ching cua table array-form: $cols[Group][id]=display
     * @param $rows danh sach chi muc hang
     * @param $groups danh sach GROUP
     * ********************************************************************************/	
    
	function edittable_2($model,$cols,$rows,$groups,$data,$data_id)
  	{
  	$result='<input type="hidden" class="cellvalue" value=""/>';
  	$result.= '<table id="tables">';
  	$result.='<th rowspan=2></th>';
  	foreach ($groups as $keyg=>$valueg):
  		$result.='<th colspan='.count($cols[$keyg]).' align="center">'.$valueg.'</th>';	
  	endforeach;
  	$result.='<th rowspan=2 class="tong">Tổng</th>';
  	$result.='<tr>';
  	$i=0;
  	foreach ($cols as $keyc => $valuec):
  		foreach ($valuec as $keyc1 => $valuec1):
  			$result.='<input type="hidden" name="data['. $model .'][col]['.$i.']" value="'. $keyc1 .'"/>';
  			$result.='<th>'.$valuec1.'</th>';
  			$i++;
  		endforeach;
  	endforeach;
  	$result.='</tr>';
  	$i=0;
  	foreach ($rows as $keyr => $valuer):
  		$result.='<tr>';
  		$result.='<input type="hidden" name="data['. $model .'][row]['. $i .']" value="'. $keyr .'"/>';
  		$result.='<td>'.$valuer.'</td>';
  		$tong=0;
  		$j=0;
  		foreach ($cols as $keyc => $valuec):
  			foreach ($valuec as $keyc1 => $valuec1):
  				$result.='<input type="hidden" name="data['. $model .'][data_tb][id]['.($i).']['.($j).']" value="'. $data_id[$keyr][$keyc1] .'"/>';
  				$result.='<td><input type="text" class="text" id="'.$i.'" name="data['.$model.'][data_tb]['.($i).']['.($j).']" value='.$data[$keyr][$keyc1].'></td>';
  				$tong+=$data[$keyr][$keyc1];
  				$j++;
  			endforeach;
  		endforeach;
  		$result.='<td><input type="text" class="tong'. $i .'" name="data['.$model.']['. $i .']["tong"]" disabled="disabled" value='.$tong.'></td>';
  		$i++;
  		$result.='</tr>';
  	endforeach;
  	$result .= '</table>';
    return $result;
    
  }

  
  
 	function show_2_table1($model,$cols_1,$cols_2,$rows,$data_1,$data_2,$datach){
   $colnum1=count($cols_1);
    $colnum2 = count($cols_2);
    $rownum=count($rows);
    $result='<table>';  
    
    $result.='<th></th>';
    $result.='<th></th>';
   /*
    * in loai col 1
    */ 
   foreach($cols_1 as $col_id_1 => $display_c_1):
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_1.'</font></b></th>';
   endforeach;
   
   /*
    * in loai col 2
    */ 
    foreach($cols_2 as $col_id_2 => $display_c_2):
        $result.='<th><b><font color="#CC0909">'.
                      $display_c_2.'</font></b></th>';
   endforeach;
   
   /*
    * in data cua tung loai col
    */
    $i=0;   
   // foreach ($rows as $row_id=>$display_r):
   for($j=0;$j<$rownum;$j++)
   {
        $result.='<tr>';
        	$result.='<td><input type="checkbox" name=data["'.$model.'"]["check'.$i.'"] value='.$datach[$rows[$j]].'/></td>';
            $result.='<td>'.$rows[$j].'</td>';
            //for($j=0;$j<$colnum1;$j++)
            for($i=0;$i<$colnum1;$i++)
            //foreach ($data_1 as $keydt1 => $valuedt1)
                  $result.='<td>'.$data_1[$j][0].'</td>';
            for($i=0;$i<$colnum2;$i++)
                  $result=$result. '<td>'. $data_2[$j][$i] .'</td>';
        
        $result.='</tr>';        
   }  
    //}
    
    $result.='</table>';
    
    return $result;
    
    
  }
  
  	function addkh($model,$chitieu=null)
  	{
  		$result ="<table>";
  		$result .="<th>STT</th>";
  		$result .="</table>";
  	}
}
 ?>